package com.swingson.properties.impl;

import com.swingson.SwingsonGui;
import com.swingson.event.ValueEvent;
import com.swingson.jsonparser.JsonElement;
import javax.swing.*;

/**
 * @author Dmitry
 */
public class NgTextPropertyProcessor extends BaseMvelPropertyProcessor {

    @Override
    public ValueEvent getEvent(JsonElement jsonElement, final JComponent component, SwingsonGui gui) {
        return new ValueEvent() {
            @Override
            protected void valueChanged(Object value) {
                String text = value == null ? "null" : value.toString();
                if (component instanceof JLabel) {
                    ((JLabel) component).setText(text);
                } else if (component instanceof JButton) {
                    ((JButton) component).setText(text);
                } else if (component instanceof JTextField) {
                    ((JTextField) component).setText(text);
                } else if (component instanceof JTextArea) {
                    ((JTextArea) component).setText(text);
                } else if (component instanceof JTextPane) {
                    ((JTextPane) component).setText(text);
                }
            }
        };
    }
}
